﻿using B.S.BasicData.Domain.Entities;
using B.S.BasicData.Error;
using B.S.BasicData.Read.Api.Application.Command.ProductsCommand;
using B.S.BasicData.Read.Api.DTO;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Read.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ProductsController : ControllerBase
    {
        private readonly IMediator mediator;

        public ProductsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 查询商品信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<ProductsDTO>> ProductsQuery([FromQuery]ProductsQueryCommand request, CancellationToken cancellationToken)
        {
             return mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 反填商品信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<ProductsDTO>>> ProductsFan([FromQuery]ProductsFanCommand request, CancellationToken cancellationToken)
        {
            return mediator.Send(request, cancellationToken);
        }
    }   
}
